<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>请假记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/resources/css/public.css" media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend style="color: #35c6d3;font-weight:bold;">已审批请假列表</legend>
</fieldset>
<div class="layuimini-container" style="padding-left:50px;padding-right: 50px;" >
    <div class="layuimini-main">
        <!-- 数据表格开始 -->
        <table class="layui-hide" id="leaveTable" lay-filter="leaveTableFilter"></table>
        <div id="currentTableBar" style="display: none;">
            <button type="button" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="check">查看</button>
<!--            <button type="button" class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</button>-->
        </div>

        <!-- 数据表格结束 -->

        <!-- 查看的弹出层开始 -->
        <div style="display: none;margin-right: 20px;" class="layui-form layuimini-form" id="addOrCheckDiv">
            <form action="" method="post" class="layui-form" id="dataFrm" lay-filter="dataFrm">
                <div style="padding-top: 20px;"></div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">学号</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="id">
                        <input type="text" name="sid" lay-verify="required" disabled="disabled" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="studentname" disabled="disabled" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">级别</label>
                    <div class="layui-input-block">
                        <input type="text" name="grade" disabled="disabled" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">班级</label>
                    <div class="layui-input-block">
                        <input type="text" name="classes" disabled="disabled" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="startdate" id="startdate" disabled="disabled" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="enddate" id="enddate" disabled="disabled" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">拒绝原因</label>
                    <div class="layui-input-block">
                        <textarea name="refusereason" disabled="disabled" class="layui-textarea"></textarea>
                    </div>
                </div>
            </form>
        </div>
        <!-- 添加和查看的弹出层结束 -->


    </div>
</div>

<script type="text/javascript" src="/resources/layui/layui.js" charset="utf-8"></script>

<script type="text/javascript">
    layui.use(['jquery', 'form', 'table', 'layer', 'layedit','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            table = layui.table,
            layedit = layui.layedit,
            layer = layui.layer;

        //日期
        laydate.render({
            elem: '#startdate',
            type: 'datetime'
        });
        laydate.render({
            elem: '#enddate',
            type: 'datetime'
        });

        //初始化富文本
        var editIndex = layedit.build('content');
        //加载数据
        var tableIns = table.render({
            elem: '#leaveTable',
            url: '/leave/loadAllLeaveApprovalCheck',
            // toolbar: '#toolbarDemo',
            cols: [
                [
                    {field: 'id', title: 'ID', width:50},
                    {field: 'sid', title: '学号', align: 'center'},
                    {field: 'studentname', title: '姓名', align: 'center'},
                    {field: 'grade', title: '级别', align: 'center'},
                    {field: 'classes', title: '班级', align: "center"},
                    {field: 'startdate', title: '开始时间', align: "center"},
                    {field: 'enddate', title: '结束时间', align: "center"},
                    {field:'status', title:'状态',align:'center',templet:function(data){
                            if (data.status == 0) {
                                return '<span class="ebe-badge ebe-tag-danger">'+'待审批';
                            }else if (data.status == 1) {
                                return '<span class="ebe-badge ebe-tag-warning">'+'已拒绝';
                            }else if(data.status==2){
                                return '<span class="ebe-badge ebe-tag-success">'+'未销假';
                            }else{
                                return '<span class="ebe-badge ebe-tag-success">'+'已销假';
                            }

                        }},
                    {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line',
            done: function (res, curr, count) { //处理删除某一页最后一条数据的BUG
                if (res.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: (curr - 1)
                        }
                    });
                }
            }
        });

        //监听行工具条的事件
        table.on("tool(leaveTableFilter)",function(obj){
            var data = obj.data; //获得当前行数据
            switch(obj.event){
                case 'check':
                    openCheckLeaveLayer(data);
                    break;
                case 'delete':
                    deleteLeave(data);
                    break;
            };
        });

        //打开查看的弹出层
        function openCheckLeaveLayer(data){
            mainIndex=layer.open({
                type:1,
                shade: 0.2,
                maxmin:true,
                shadeClose: true,
                content:$("#addOrCheckDiv"),
                area:['800px','600px'],
                title:'查看假单',
                success:function(){
                    $("#dataFrm")[0].reset();
                    //装载新的数据
                    form.val("dataFrm",data);
                }
            });
        }

        //删除
        function deleteLeave(data){
            layer.confirm('你确定要删除【'+data.studentname+'】这条假单吗?', {icon: 3, title:'提示'}, function(index){
                $.post("/deleteLeave",{id:data.id},function(res){
                    if(res.code==200){
                        tableIns.reload();
                    }
                    layer.msg(res.msg);
                })
                layer.close(index);
            });
        }
    });
</script>

</body>
</html>